package com.itheima.api.collection.demo04;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class CollectionDemo01 {

    public static void main(String[] args) {

        Student s1 = new Student("刘德华", 45);
        Student s2 = new Student("古天乐", 46);
        Student s3 = new Student("张家辉", 47);

        Collection<Student> col = new ArrayList<Student>();

        col.add(s1);
        col.add(s2);
        col.add(s3);

        //1.迭代器
        Iterator<Student> iterator = col.iterator();
        while (iterator.hasNext()){
            Student next = iterator.next();
            System.out.println(next.getName() + "----" + next.getAge());
        }

        System.out.println("---------------------------------------------");

        //2.增强for循环
        for(Student s : col){
            System.out.println(s.getName() + "----" + s.getAge());
        }

        System.out.println("---------------------------------------------");

        //3.forEach
        col.forEach(s -> System.out.println(s.getName() + "----" + s.getAge()));

    }

}
